import pandas as pd
import my_jdbc as jdbc
import json
import run_request_service as res

if __name__ == '__main__':
    file_name_path = "C:\\Users\\xyh\\Desktop\\流程.xlsx"
    data = pd.read_excel(file_name_path, sheet_name='Sheet3', usecols=['计划', '流程', '工序', '工步'])
    data.dropna(subset=['计划', '流程', '工序', '工步'], inplace=True)
    res.login('712017165048788d32c953896cc7ce4a')
    for index, row in data.iterrows():
        plan_info = """
              select id from kc_production_plan where production_code = '{0}';
             """.format(row['计划'])
        one = jdbc.kcdoc_search_one(plan_info)
        json_file = res.getLcInfo(row['流程'])
        data = json.loads(json_file)
        for step in data.get("data")[0].get("processStep", []):
            if step.get("gxmc") == row['工序']:
                wxjc_step = step
                break
        if wxjc_step:
            processSteps = []
            processStep = {"processNo": wxjc_step.get("processNo"),
                           "processName": wxjc_step.get("gxmc"),
                           "timeOut": wxjc_step.get("timeOut"),
                           "ratedWorkTime": wxjc_step.get("ratedWorkTime"),
                           "processRoleName": wxjc_step.get("processRoleName"),
                           "processRole": wxjc_step.get("processRole"),
                           "workshopName": wxjc_step.get("firstSelectedWorkshopName"),
                           "workshopId": wxjc_step.get("firstSelectedWorkshopId"),
                           "quality": 0,
                           "stepId": wxjc_step.get("stepId"),
                           "resume": "",
                           "maxTaskUser": wxjc_step.get("maxTaskUser"),
                           "maxDoingUser": wxjc_step.get("maxDoingUser"),
                           "useTools": wxjc_step.get("useTools"),
                           "attributeList": wxjc_step.get("attributeList"),
                           "toolsMaterialNumber": wxjc_step.get("toolsMaterialNumber"),
                           "solidId": wxjc_step.get("solidId"),
                           "solidName": wxjc_step.get("solidName"),
                           "cncList": wxjc_step.get("cncList"),
                           "cncFileList": wxjc_step.get("cncFileList"),
                           "cncSourceList": wxjc_step.get("cncSourceList"),
                           "cncCostTime": wxjc_step.get("cncCostTime"),
                           "stepDeviceList": wxjc_step.get("stepDeviceList")
                           }
            processSteps.append(processStep)
            add_json = {"lcbh": row['流程'],
                        "id": one[0],
                        "processIndex": row['工步'],
                        "bank": "1",
                        "processStep": processSteps
                        }
            print(add_json)
            res.add_lc_person(add_json)
